﻿using SW.Model;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace SW.Core
{
    /// <summary>
    /// 配置辅助类
    /// </summary>
    public static class ConfigHelper
    {
        /// <summary>
        /// 根据键取值
        /// </summary>
        /// <param name="key">键</param>
        public static string GetAppSettingsValue(string key)
        {
            return ConfigurationManager.AppSettings[key].ToString().Trim();
        }

        /// <summary>
        /// 根据键修改值
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        public static void SetAppSettingsValue(string key, string value)
        {
            ConfigurationManager.AppSettings.Set(key, value);
        }

        /// <summary>
        /// 添加新的键值对
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        public static void AddAppSettings(string key, string value)
        {
            ConfigurationManager.AppSettings.Add(key, value);
        }

        /// <summary>
        /// 根据键删除项
        /// </summary>
        /// <param name="key">键</param>
        public static void RemoveAppSettings(string key)
        {
            ConfigurationManager.AppSettings.Remove(key);
        }

        /// <summary>
        /// 根据键取连接字符串
        /// </summary>
        /// <param name="key">键</param>
        public static string GetConnectionString(string key)
        {
            return ConfigurationManager.ConnectionStrings[key].ToString().Trim();
        }
    }
}
